#include "StdAfx.h"
#include "DsnCircuitPinDisObj.h"
#include "DsnCircuitPin.h"

DsnCircuitPin::DsnCircuitPin(void)
{
	m_bDotSymbol = false;
	m_bClKSymbol = false;
	m_bHide = false;
	m_bShowPinName = false;
	m_bShowPinIndex = false;
	m_dblPinLength = 0.0;
	m_dblPosX = 0.0;
	m_dblPosY = 0.0;
	m_rotateAngle = 0.0;
	m_bSelected = false;
	m_szPinName = _T("");
	m_szPinIndex = _T("");
}

DsnCircuitPin::DsnCircuitPin(const DsnCircuitPin *pEntityObj)
	: CCircuitUnit(pEntityObj)
{
	m_bDotSymbol = pEntityObj->IsExistDotSymbol();
	m_bClKSymbol = pEntityObj->IsExistClkSymbol();
	//m_elecCharac = pEntityObj->GetElecCharacter();
	m_bHide = pEntityObj->IsHide();
	m_bShowPinName = pEntityObj->IsShowPinName();
	m_bShowPinIndex = pEntityObj->IsShowPinIndex();
	m_dblPinLength = pEntityObj->GetPinLength();
	m_dblPosX = pEntityObj->GetPosX();
	m_dblPosY = pEntityObj->GetPosY();
	m_rotateAngle = pEntityObj->GetRotaAngle();
	m_bSelected = pEntityObj->IsSelected();
	m_szPinName = pEntityObj->GetPinName();
	m_szPinIndex = pEntityObj->GetPinIndex();
}

DsnCircuitPin::DsnCircuitPin(CICircuit *pParentEnt)
	: CCircuitUnit(pParentEnt)
{
	m_bDotSymbol = false;
	m_bClKSymbol = false;
	m_bHide = false;
	m_bShowPinName = false;
	m_bShowPinIndex = false;
	m_dblPinLength = 0.0;
	m_dblPosX = 0.0;
	m_dblPosY = 0.0;
	m_rotateAngle = 0.0;
	m_bSelected = false;
	m_szPinName = _T("");
	m_szPinIndex = _T("");
}

DsnCircuitPin::~DsnCircuitPin(void)
{
}

void DsnCircuitPin::Serialize(CArchive & ar)
{
	if (ar.IsStoring())
	{
		ar << m_bDotSymbol;
		ar << m_bClKSymbol;
		ar << m_bHide;
		ar << m_bShowPinName;
		ar << m_bShowPinIndex;
		ar << m_dblPinLength;
		ar << m_dblPosX;
		ar << m_dblPosY;
		ar << m_rotateAngle;
		ar << m_bSelected;
		CObj::WriteString(ar, m_szPinName);
		CObj::WriteString(ar, m_szPinIndex);
	}
	else
	{
		ar >> m_bDotSymbol;
		ar >> m_bClKSymbol;
		int nElecCharacter(0);
		ar >> nElecCharacter;
		ar >> m_bHide;
		ar >> m_bShowPinName;
		ar >> m_bShowPinIndex;
		ar >> m_dblPinLength;
		ar >> m_dblPosX;
		ar >> m_dblPosY;
		ar >> m_rotateAngle;
		ar >> m_bSelected;
		CObj::ReadString(ar, m_szPinName);
		CObj::ReadString(ar, m_szPinIndex);
	}

	CCircuitUnit::Serialize(ar);
}

CObj *DsnCircuitPin::Clone() const
{
	return new DsnCircuitPin(this);
}

void DsnCircuitPin::Transform(const CMatrix transf)
{

}

bool DsnCircuitPin::GetBox(double & dblLeft, double & dblBottom, double & dblRight, double & dblTop) const
{
	return CCircuitUnit::GetBox(dblLeft, dblBottom, dblRight, dblTop);
}

void DsnCircuitPin::Clear()
{

}

void DsnCircuitPin::CopyDisplayObj(long lSourceLayerId, long lDestLayerId)
{
	CEntityObj::CopyDisplayObj(lSourceLayerId, lDestLayerId);
}

void DsnCircuitPin::DeleteDisplayObj(long lLayerId)
{
	CEntityObj::DeleteDisplayObj(lLayerId);
}

CDisplayObj * DsnCircuitPin::CreateDisplayObj(long lLayerId)
{
	DsnCircuitPinDisObj *pPinDis = new DsnCircuitPinDisObj(this);
	pPinDis->SetLayerId(lLayerId);
	return pPinDis;
}

void DsnCircuitPin::CalcBox()
{
	m_minX = m_maxX = m_dblPosX;
	m_minY = m_maxY = m_dblPosY;

	eRotateType rotaType;
	if (fabs(m_rotateAngle-0.0) < 1e-6)
	{
		rotaType = Rotate_0_degree;
		m_maxX = m_dblPosX + m_dblPinLength;
	}
	else if (fabs(m_rotateAngle-90.0) < 1e-6)
	{
		rotaType = Rotate_90_degree;
		m_maxY = m_dblPosY + m_dblPinLength;
	}
	else if (fabs(m_rotateAngle-180.0) < 1e-6)
	{
		rotaType = Rotate_180_degree;
		m_minX = m_dblPosX - m_dblPinLength;
	}
	else if (fabs(m_rotateAngle-270.0) < 1e6)
	{
		rotaType = Rotate_270_degree;
		m_minY = m_dblPosY - m_dblPinLength;
	}
}

eCircuitUnitEntType DsnCircuitPin::GetUnitType() const
{
	return TINYCAD_CIRCUIT_PIN;
}

bool DsnCircuitPin::IsExistDotSymbol() const
{
	return m_bDotSymbol;
}

bool DsnCircuitPin::IsExistClkSymbol() const
{
	return m_bClKSymbol;
}

//eElectriCharacter DsnCircuitPin::GetElecCharacter() const
//{
//	return m_elecCharac;
//}

bool DsnCircuitPin::IsHide() const
{
	return m_bHide;
}

bool DsnCircuitPin::IsShowPinName() const
{
	return m_bShowPinName;
}

bool DsnCircuitPin::IsShowPinIndex() const
{
	return m_bShowPinIndex;
}

double DsnCircuitPin::GetPinLength() const
{
	return m_dblPinLength;
}

double DsnCircuitPin::GetPosX() const
{
	return m_dblPosX;
}

double DsnCircuitPin::GetPosY() const
{
	return m_dblPosY;
}

double DsnCircuitPin::GetRotaAngle() const
{
	return m_rotateAngle;
}

bool DsnCircuitPin::IsSelected() const
{
	return m_bSelected;
}

CString DsnCircuitPin::GetPinName() const
{
	return m_szPinName;
}

CString DsnCircuitPin::GetPinIndex() const
{
	return m_szPinIndex;
}

void DsnCircuitPin::SetExistDotSymbol(bool bFlag) 
{
	m_bDotSymbol = bFlag;
}

void DsnCircuitPin::SetExistClkSymbol(bool bFlag) 
{
	m_bClKSymbol = bFlag;
}

//void DsnCircuitPin::SetElecCharacter(eElectriCharacter elecChar) 
//{
//	m_elecCharac = elecChar;
//}

void DsnCircuitPin::SetHide(bool bFlag) 
{
	m_bHide = bFlag;
}

void DsnCircuitPin::SetShowPinName(bool bFlag) 
{
	m_bShowPinName = bFlag;
}

void DsnCircuitPin::SetShowPinIndex(bool bFlag) 
{
	m_bShowPinIndex = bFlag;
}

void DsnCircuitPin::SetPinLength(double dblLen) 
{
	m_dblPinLength = dblLen;
}

void DsnCircuitPin::SetPosX(double posX) 
{
	m_dblPosX = posX;
}

void DsnCircuitPin::SetPosY(double posY)
{
	m_dblPosY = posY;
}

void DsnCircuitPin::SetRotaAngle(double dblAngle) 
{
	m_rotateAngle = dblAngle;
}

void DsnCircuitPin::SetSelected(bool bFlag) 
{
	m_bSelected = bFlag;
}

void DsnCircuitPin::SetPinName(CString szName) 
{
	m_szPinName = szName;
}

void DsnCircuitPin::SetPinIndex(CString szIndex) 
{
	m_szPinIndex = szIndex;
}

//CString DsnCircuitPin::GetElecCharacterName() const
//{
//	switch (m_elecCharac)
//	{
//	case ELECTR_CHARACTER_INPUT:
//		return _T("input");
//	case ELECTR_CHARACTER_IO:
//		return _T("IO");
//	case ELECTR_CHARACTER_OUTPUT:
//		return _T("output");
//	case ELECTR_CHARACTER_OPENCOLLECTOR:
//		return _T("open collector");
//	case ELECTR_CHARACTER_PASSIVE:
//		return _T("passive");
//	case ELECTR_CHARACTER_HIZ:
//		return _T("hiz");
//	case ELECTR_CHARACTER_OPENEMITTER:
//		return _T("open emitter");
//	case ELECTR_CHARACTER_POWER:
//		return _T("power");
//	default:
//		return _T("unknow");
//	}
//}